function load_gadget() {
	var view = dojo.byId('view_type').value;
	if (dojo.byId('spec_field_input').value == '') {
		var url = dojo.byId('spec_field').value
	}
	else {
		var url = dojo.byId('spec_field_input').value
	}
	requestGadgetMetaData(url, view);
}

function get_spec_url() {
	if (dojo.byId('spec_field_input').value == '') {
		url = dojo.byId('spec_field').value
	}
	else {
		url = dojo.byId('spec_field_input').value
	}
	return url;
}

function render_metadata(data) {
	var url = 'gadget_viewer/display_metadata';
	var metadata = eval('(' + data + ')');
	dojo.xhrPost({
	    url: url,
		postData: 'spec_url=' + get_spec_url() + '&json=' + escape(dojo.toJson(metadata)),
	    timeout: 6000, // give up after 6 seconds
		load: display_metadata,
		error: display_metadata_error
	});
}

function display_metadata(data) {
	document.getElementById('metadata_display').innerHTML = data;
	renderGadget(iframe_url);
}

function display_metadata_error(error) {
	alert('display_metadata_error ERROR: ' + dumpObj(error));
}

function switch_tabs(tab_num) {
	select_tab(tab_num);	
}

function select_tab(num) {
	hide_all_tabs();
	document.getElementById('tab'+num).style.display = 'block';
	deselect_all_tabs()
	document.getElementById('tabEl'+num).className = "selected_tab";
}

function hide_all_tabs() {
	document.getElementById('tab1').style.display = 'none';
	document.getElementById('tab2').style.display = 'none';
	document.getElementById('tab3').style.display = 'none';
	document.getElementById('tab4').style.display = 'none';
	document.getElementById('tab5').style.display = 'none';
	document.getElementById('tab6').style.display = 'none';
	document.getElementById('tab7').style.display = 'none';
	document.getElementById('tab8').style.display = 'none';
	document.getElementById('tab9').style.display = 'none';
}

function deselect_all_tabs() {
	document.getElementById('tabEl1').className = "";
	document.getElementById('tabEl2').className = "";
	document.getElementById('tabEl3').className = "";
	document.getElementById('tabEl4').className = "";
	document.getElementById('tabEl5').className = "";
	document.getElementById('tabEl6').className = "";
	document.getElementById('tabEl7').className = "";
	document.getElementById('tabEl8').className = "";
	document.getElementById('tabEl9').className = "";
}
